package com.huihuiyun.huihuiyun.server.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.map.PassiveExpiringMap;
import org.springframework.stereotype.Component;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Component
@Path("/redis")
@Slf4j
public class MockRedisService {
    private PassiveExpiringMap<String, String> dataMap = new PassiveExpiringMap(10 * 60 * 1000); // Expiration time of 1 sec

    @GET
    @Path("/set")
    public void set(String key, String value) {
        dataMap.put(key, value);
    }

    @GET
    @Path("/get")
    public String get(String key) {
        return dataMap.get(key);
    }

    @GET
    @Path("/delete")
    public void delete(String key) {
        if (dataMap.containsKey(key)) {
            dataMap.remove(key);
        }
    }
}
